package fr.esiag.isidis.web;

import java.util.ArrayList;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import fr.esiag.isidis.service.ExportServiceImpl;

/**
 * 
 * @author MEDINI
 *
 */

/**
 * Handles requests for the application home page.
 */

@Controller
public class ExportController {
	
	private static final Logger logger = LoggerFactory.getLogger(ExportController.class);
	
	//page d'accueil
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String home() {
		return "home";
	}
	
	//methode d'export du fichier XML
	@RequestMapping(value = "/exportXML", method = RequestMethod.POST)
	public String exportXML(@RequestParam("beginDate") Date beginDate,
			@RequestParam("endDate") Date endDate,
			@RequestParam("sites") String [] sites, Model model) {
		
		ExportServiceImpl exportServ = new ExportServiceImpl();
		
		byte[] dataExportXML = exportServ.exportXML(beginDate, endDate, sites);
		
		return "exportXML";
	}
	
	//methode d'export du fichier XML
	@RequestMapping(value = "/exportCSV", method = RequestMethod.POST)
	public String exportCSV(@RequestParam("beginDate") Date beginDate,
			@RequestParam("endDate") Date endDate,
			@RequestParam("sites") String [] sites, Model model) {
		
		ExportServiceImpl exportServ = new ExportServiceImpl();
		
		byte[] dataExportCSV = exportServ.exportCSV(beginDate, endDate, sites);
		
		return "exportCSV";
	}
	
	
	//methode de visualisation de graphe
	@RequestMapping(value="/display", method = RequestMethod.POST, produces = "application/json")
	@ResponseBody
	public CDCModel display(@RequestParam("beginDate") Date beginDate,
			@RequestParam("endDate") Date endDate,
			@RequestParam("sites") String [] export, Model model) {
		
		CDCModel cdcModel = new CDCModel();
		cdcModel.setDates("11/12/1976");
		ArrayList<Integer> list = new  ArrayList<Integer>();
		list.add(1);
		list.add(6);
		list.add(12);
		cdcModel.setCharge(list);
		return cdcModel;
	}

}
